package com.googlecode.cswish.struts.hibernate;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

/**
 * Try to load the session factory if current environment is hibernate JPA
 * 	 
 * @author jerry.feng Date: 2009-2-11
 */
public class JPASessionFactory {

	private SessionFactory factory;
	
	@PersistenceContext
	public void setEntityManager(EntityManager em) {
		Object delegate = em.getDelegate();
		Session session = (Session) delegate;
		this.factory = session.getSessionFactory();
	}
	
	protected SessionFactory getSessionFactory() {
		return this.factory;
	}
}
